<?php
class OmonsController extends AppController {

	var $name = 'Omons';

	function beforeRender() {
		$groupid = $this->Auth->user('group_id');
		$name = 'Omons';
		IF($groupid != 1){
			$result1 = mysql_query("SELECT id FROM applications WHERE name = '$name'");
			$appid = mysql_fetch_object($result1)->id;
			$result2 = mysql_query("SELECT count(*) as count FROM groupshasrights WHERE group_id = '$groupid' AND application_id = '$appid'");
			$count = mysql_fetch_object($result2)->count;
			IF($count == 0){
				$this->Session->setFlash(__('Access Denied', true));
				$this->redirect(array('controller' => 'pages' ,'action' => 'error'));	
			}
		}
	}
	
	function findPR($account){
		$status1 = "Cancelled"; $status2 = "Closed"; $status3 = "Hard Closed";
		$sql = "SELECT COUNT(*) AS COUNT FROM omondatas WHERE account_number = '$account' AND x_to NOT IN ('$status1','$status2','$status3')";
	    $counter = $this->Omon->query($sql);
	    return $counter['0']['0']['COUNT'];		
	}

	
}
?>